//
//  THCustomServiceViewController.m
//  TreeHole
//
//  Created by apple on 2020/9/17.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THCustomServiceViewController.h"

@interface THCustomServiceViewController ()
@property(nonatomic, strong) STButton                     *stoneobs_ui_clearButton;
@property(nonatomic, strong) UIView                     *stoneobs_ui_customView;
@end

@implementation THCustomServiceViewController

- (instancetype)init
{
    if (self == [super init]) {
        self.modalPresentationStyle = UIModalPresentationOverFullScreen;
    }
    return self;
}
#pragma mark --vc 生命周期
- (void)viewDidLoad{
    [super viewDidLoad];
    [self stoneobs_ui_configSubView];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self stoneobs_fun_show];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)stoneobs_ui_configSubView{
    self.view.backgroundColor = UIColor.clearColor;
    __weak typeof(self) weakSelf =  self;
    self.stoneobs_ui_clearButton = [[STButton alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME
                                                             title:nil
                                                        titleColor:nil
                                                         titleFont:0
                                                      cornerRadius:0
                                                   backgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.4]
                                                   backgroundImage:nil
                                                             image:nil];
    [weakSelf.stoneobs_ui_clearButton setClicAction:^(UIButton *sender) {
        [weakSelf stoneobs_fun_dismiss];
    }];
    [self.view addSubview:_stoneobs_ui_clearButton];
    
    self.stoneobs_ui_customView = [[UIView alloc] initWithFrame:CGRectMake(40, 0, UISCREEN_WIDTH - 80, 200)];
    self.stoneobs_ui_customView.centerX = UISCREEN_WIDTH / 2;
    self.stoneobs_ui_customView.top = UISCREEN_HEIGHT;
    self.stoneobs_ui_customView.backgroundColor = [UIColor whiteColor];
    self.stoneobs_ui_customView.layer.cornerRadius = 10;
    self.stoneobs_ui_customView.clipsToBounds = YES;
    [self.view addSubview:self.stoneobs_ui_customView];
    
    STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(0, 20, self.stoneobs_ui_customView.width , 20)
                                                            text:@"客服"
                                                       textColor:UIColor.blackColor
                                                            font:15
                                                     isSizetoFit:NO
                                                   textAlignment:NSTextAlignmentCenter];
    [self.stoneobs_ui_customView addSubview:stoneobs_ui_label];
    stoneobs_ui_label.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:20];
    
    CGFloat top = stoneobs_ui_label.bottom + 30;
    ({
        NSString * title = self.wechat;
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH , 30)
                                                                text:[NSString stringWithFormat:@"微信号:%@",title]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.stoneobs_ui_customView addSubview:stoneobs_ui_label];
        
        STButton * copybutton = [[STButton alloc] initWithFrame:CGRectMake(0, top, 30, 30)
                                                                 title:@"复制"
                                                           titleColor:WH_UICOLOR_FROM_RGBA(0x0078FF)
                                                       titleFont:13
                                                    cornerRadius:0
                                                 backgroundColor:nil
                                                 backgroundImage:nil
                                                           image:nil];
        copybutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        copybutton.right = self.stoneobs_ui_customView.width - 15;
        [copybutton setClicAction:^(UIButton *sender) {
            [UIPasteboard.generalPasteboard setString:title];
            [SVProgressHUD showSuccessWithStatus:@"复制成功"];
        }];
        [self.stoneobs_ui_customView addSubview:copybutton];
        
        top = copybutton.bottom + 10;
    });

    ({
        NSString * title = self.phone;
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, STONEOBS_UI_UISCREEN_WIDTH , 30)
                                                                text:[NSString stringWithFormat:@"电话:%@",title]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.stoneobs_ui_customView addSubview:stoneobs_ui_label];
        
        STButton * copybutton = [[STButton alloc] initWithFrame:CGRectMake(0, top, 30, 30)
                                                           title:@"拨打"
                                                     titleColor:WH_UICOLOR_FROM_RGBA(0x0078FF)
                                                       titleFont:13
                                                    cornerRadius:0
                                                 backgroundColor:nil
                                                 backgroundImage:nil
                                                           image:nil];
        copybutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        copybutton.right = self.stoneobs_ui_customView.width - 15;
        [copybutton setClicAction:^(UIButton *sender) {
            NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",title];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:nil completionHandler:^(BOOL success) {
                
            }];
        }];
        [self.stoneobs_ui_customView addSubview:copybutton];
        
        top = copybutton.bottom + 10;
    });
    
    STButton * okbutton = [[STButton alloc] initWithFrame:CGRectMake(0, top, self.stoneobs_ui_customView.width, 44)
                                                       title:@"好的"
                                                 titleColor:WH_UICOLOR_FROM_RGBA(0x0078FF)
                                                   titleFont:15
                                                cornerRadius:0
                                             backgroundColor:nil
                                             backgroundImage:nil
                                                       image:nil];
    okbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [okbutton setClicAction:^(UIButton *sender) {
        [weakSelf stoneobs_fun_dismiss];
    }];
    [self.stoneobs_ui_customView addSubview:okbutton];
    
    self.stoneobs_ui_customView.height = okbutton.bottom;
    [okbutton stoneobs_fun_st_showTopLine];
    
    self.stoneobs_ui_customView.top = UISCREEN_HEIGHT;
    
    
}

- (void)stoneobs_fun_show{
    [UIView animateWithDuration:0.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:0.7
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
        self.stoneobs_ui_customView.centerY = UISCREEN_HEIGHT/2;
    } completion:^(BOOL finished) {
        
    }];
}
- (void)stoneobs_fun_dismiss{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.stoneobs_ui_customView.top = UISCREEN_HEIGHT;
        self.stoneobs_ui_clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}
- (void)stoneobs_fun_dismissWithHandle:(void(^)(void))handle{
    [self.view endEditing:YES];
    [UIView animateWithDuration:0.25 animations:^{
        self.stoneobs_ui_customView.top = UISCREEN_HEIGHT;
        self.stoneobs_ui_clearButton.alpha = 0;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:^{
            if (handle) {
                handle();
            }
        }];
    }];
}

@end
